package cn.bailin233.web.utils;

import cn.bailin233.web.enums.CodeEnum;
import lombok.Data;

@Data
public class ResultUtil {

    private int code;
    private String msg;
    private Object data;

    public static ResultUtil success(Object data) {
        return resultData(CodeEnum.SUCCESS.val(), CodeEnum.SUCCESS.msg(), data);
    }

    public static ResultUtil success(String msg, Object data) {
        return resultData(CodeEnum.SUCCESS.val(), msg, data);
    }

    public static ResultUtil error() {
        return resultData(CodeEnum.ERROR.val(), CodeEnum.ERROR.msg(), null);
    }

    public static ResultUtil error(String msg) {
        return resultData(CodeEnum.ERROR.val(), msg, null);
    }

    public static ResultUtil error(int code, String msg) {
        return resultData(code, msg, null);
    }

    public static ResultUtil resultData(int code, String msg, Object data) {
        ResultUtil resultData = new ResultUtil();
        resultData.setCode(code);
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }
}
